/**
 * 
 */
package edu.sjtu.se.prophet.io.gson;

import java.lang.reflect.Type;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;

import edu.sjtu.se.prophet.graph.Edge;

/**
 * @author willard
 * 
 */
public class EdgeSerializer implements JsonSerializer<Edge> {

    @Override
    public JsonElement serialize(Edge edge, Type type,
            JsonSerializationContext context) {
        JsonObject edgeObject = new JsonObject();
        edgeObject.addProperty("start", edge.getStart().getId());
        edgeObject.addProperty("end", edge.getEnd().getId());
        edgeObject.add("metrics", context.serialize(edge.getMetrics()));
        return edgeObject;
    }

}
